touhouvnfandomcom-20200216-history
Loadmenu rpy
Coding and VN Engine > loadmenu_rpy Save/Load Menu init python: page = 1 ## number of save slots save_col = 5 save_row = 2 sn = save_col * save_row sn = sn + 1 selected_slot = 0 screenshot = None*sn chptitles = None*sn titlesplit = None*sn ######## ##Config## ######## ##Page Text Style style.pfont = Style(style.default) style.pfont.size = 10 style.pfont.xanchor = 'center' style.pfont.xpos = 0.5 ##Save Text Style style.sfont = Style(style.default) style.sfont.size = 15 style.sfont.xanchor = 'right' style.sfont.xpos = 1.0 ##Save File Variables return_day = "Day -" return_playtime = "---------" chptitle = "---------" dayp, hourp, minp, secp = ("--","--","--","--") sday, smonth, syear, shour, smin = ("--","--","--","--","--") stime = ("--") selected_ss = "img/nosave.png" def calc_played(): import math minp, secp = divmod(int(math.floor(float(store.return_played) + .5)), 60) hourp, minp = divmod(minp, 60) dayp, hourp = divmod(hourp, 24) if dayp 0: dayp = "" else: dayp = "%sd" % (dayp) if hourp 0: hourp = "" else: hourp = "%sh" % (hourp) if minp 0: minp = "" else: minp = "%sm" % (minp) if secp 0: secp = "" else: secp = "%ss" % (secp) store.return_playtime = ("%s %s %s %s" % (dayp, hourp, minp, secp)) return ## Adds to page count def add_page(): if store.page < 10: store.page = store.page + 1 return ## Subtracts from page count def sub_page(): page = store.page if page > 1: store.page = page - 1 return ## Checks the save availability and loads the corresponding images def init_slots(): sn = store.sn for i in range (1, sn): if renpy.can_load("slot%s" % ((sn-1) * (page-1) + i)): store.datas = renpy.scan_saved_game("slot%s" % ((sn-1) * (page-1) + i)) store.chptitlesi = "%s" % (store.datas0) titlespliti = store.chptitlesi.split('-') store.screenshoti ="img/%s %s.png" % (titlespliti0, titlespliti1) else: store.screenshoti ="img/nosave.png" return ## Creates a load slot def create_lslot(a): ui.imagebutton(im.Grayscale(im.Scale(screenshota, 80, 60)), im.Scale(screenshota, 80, 60), clicked= lambda: load_click(a), hovered= lambda: (init_hover(a), renpy.jump('load_menu')), xpadding=10 ) ## When clicking a loading slot def load_click(a): selected_slot = "slot%s" % ((store.sn - 1) * (store.page-1) + a) if renpy.can_load(selected_slot): ui.imagebutton(Solid((0, 0, 0, 100)), Solid((0, 0, 0, 100)), clicked=ui.jumps('load_menu'), xfill=True, yfill=True)## prevents clicking on the slots ui.hbox() ui.frame(background=None, ypos=0.5, yanchor='center') ui.text('Load this File?') ui.textbutton('Yes',clicked= lambda: renpy.load(selected_slot)) ui.textbutton('No',clicked= ui.jumps('load_menu')) ui.close() else: return ui.interact(suppress_overlay=True, suppress_underlay=True, mouse='gamemenu') return ## Creates a save slot def create_sslot(a): ui.imagebutton(im.Grayscale(im.Scale(screenshota, 80, 60)), im.Scale(screenshota, 80, 60), clicked= lambda: save_click(a), hovered= lambda: (init_hover(a), renpy.jump('save_menu')), xpadding=10 ) ## When clicking a saving slot def save_click(a): selected_slot = "slot%s" % ((store.sn - 1) * (store.page-1) + a) save_day = store.save_day save_title = store.save_title game_played = "%s" % (store.game_played) array = (save_title, game_played) t = '-' chaptername = t.join(array) if renpy.can_load(selected_slot): ui.imagebutton(Solid((0, 0, 0, 100)), Solid((0, 0, 0, 100)), clicked=ui.jumps('save_menu'), xfill=True, yfill=True) ## prevents clicking on the slots ui.hbox() ui.frame(background=None, ypos=0.5, yanchor='center') ui.text('Save over this File?') ui.textbutton('Yes',clicked= lambda: (renpy.take_screenshot(),renpy.save("%s" % (selected_slot), chaptername), renpy.jump('save_menu'))) ui.textbutton('No',clicked= ui.jumps('save_menu')) ui.close() ui.interact(suppress_overlay=True, suppress_underlay=True, mouse='gamemenu') return else: renpy.take_screenshot() renpy.save("%s" % (selected_slot), chaptername) renpy.jump('save_menu') return ## Multi-use hover over slot def init_hover(a): selected_slot = "slot%s" % ((store.sn - 1) * (store.page-1) + a) store.selected_ss = screenshota if renpy.can_load(selected_slot): data = renpy.scan_saved_game(selected_slot) store.chptitle = "%s" % (data0) ## Extract day, title, and time played titlesplit = store.chptitle.split("-") store.return_day = titlesplit0 store.chptitle = titlesplit1 store.return_played = titlesplit2 calc_played() ## Extract time data and format import time ttemp = time.localtime(data2) syear = ttemp0 smonth = ttemp1 sday = ttemp2 shour = ttemp3 smin = ttemp4 ssec = ttemp5 if smonth < 10: smonth = "0%s" % (smonth) if sday < 10: sday = "0%s" % (sday) if shour > 11: stime = "PM" else: stime = "AM" if shour > 12: shour = "%s" % (shour - 12) if shour 0: shour = "%s" % (12) if smin < 10: smin = "0%s" % (smin) if ssec < 10: ssec = "0%s" % (ssec) ## Stores time data and format store.smin, store.shour, store.sday, store.smonth, store.syear, store.stime = ("%s" % (smin),"%s" % (shour),"%s" % (sday),"%s" % (smonth),"%s" % (syear), "%s" % (stime)) else: ## Blank load/save slot store.return_day = "Day -" store.return_playtime = "---------" store.chptitle = "---------" store.sday, store.smonth, store.syear, store.shour, store.smin = ("--","--","--","--","--") store.stime = ("--") store.dayp, store.hourp, store.minp, store.secp = ("--","--","--","--") return ############### ###Loading Section## ############### label load_menu: $ init_slots() $ ui.image(ui_background) ## $ ui.image(ui_topborder, ## xpos=0, ## ypos=0 ## ) ## $ ui.image(ui_botborder, ## xpos=0, ## ypos=500 ## ) $ ui.image("img/loadmenuback.png") ##Container $ ui.frame(background=None, xpos=0.5, ypos=0.5, xanchor='center', yanchor='center') $ ui.vbox() ######## ##Screenshot Viewer $ ui.frame(background=Solid((0, 0, 0, 0)), xanchor='center', xpos=0.5) $ ui.image(selected_ss) ##Day and Title and Playtime and Date $ ui.frame(background=Solid((0, 0, 0, 0)), xanchor='center', xpos=0.5) $ ui.hbox() $ ui.frame(background=None, xminimum=75) $ ui.text("%s" % (return_day), style='sfont') $ ui.frame(background=None, xminimum=250) $ ui.text("%s" % (chptitle), style='sfont') $ ui.frame(background=None, xminimum=100) $ ui.text("%s" % (return_playtime), style='sfont') $ ui.frame(background=None, xminimum=200) $ ui.text("%s/%s/%s %s:%s %s" % (smonth, sday, syear, shour, smin, stime), style='sfont') $ ui.close() ##Slot Grid and Navigation $ ui.frame(background=Solid((0, 0, 0, 0)), xanchor='center', xpos=0.5) $ ui.hbox() $ ui.textbutton("<<", yanchor='center', ypos=0.5, clicked= lambda: (sub_page(), renpy.jump('load_menu')) ) $ ui.grid(save_col, save_row, padding=12, transpose=False) $ for i in range(1, sn): create_lslot(i) $ ui.close() $ ui.textbutton(">>", yanchor='center', ypos=0.5, clicked= lambda: (add_page(), renpy.jump('load_menu')) ) $ ui.close() ##Page Number $ ui.sizer(maxwidth=182, xanchor='center', xpos=0.5) $ ui.frame(background=None,xanchor='center', xpos=0.5, xfill=True) $ ui.text("Page %s" % (page),style='pfont') ##Return Button $ ui.imagebutton(ui_return1, ui_return2, clicked=ui.jumps("_return"), xpos=1.0, xanchor='right', yanchor='center' ) $ ui.close()##closes general vbox $ ui.interact(suppress_overlay=True, suppress_underlay=True, mouse='mainmenu') return ############### ###Saving Section## ############### label save_menu: $ init_slots() $ ui.image(ui_background) ## $ ui.image(ui_topborder, ## xpos=0, ## ypos=0 ## ) ## $ ui.image(ui_botborder, ## xpos=0, ## ypos=500 ## ) $ ui.image("img/loadmenuback.png") ##Container $ ui.frame(background=None, xpos=0.5, ypos=0.5, xanchor='center', yanchor='center') $ ui.vbox() ##Screenshot Viewer $ ui.frame(background=Solid((0, 0, 0, 0)), xanchor='center', xpos=0.5) $ ui.image(selected_ss) ##Day and Title and Playtime and Date $ ui.frame(background=Solid((0, 0, 0, 0)), xanchor='center', xpos=0.5) $ ui.hbox() $ ui.frame(background=None, xminimum=75) $ ui.text("%s" % (return_day), style='sfont') $ ui.frame(background=None, xminimum=250) $ ui.text("%s" % (chptitle), style='sfont') $ ui.frame(background=None, xminimum=100) $ ui.text("%s" % (return_playtime), style='sfont') $ ui.frame(background=None, xminimum=200) $ ui.text("%s/%s/%s %s:%s %s" % (smonth, sday, syear, shour, smin, stime), style='sfont') $ ui.close() ##Slot Grid and Navigation $ ui.frame(background=Solid((0, 0, 0, 0)), xanchor='center', xpos=0.5) $ ui.hbox() $ ui.textbutton("<<", yanchor='center', ypos=0.5, clicked= lambda: (sub_page(), renpy.jump('save_menu')) ) $ ui.grid(save_col, save_row, padding=12, transpose=False) $ for i in range(1, sn): create_sslot(i) $ ui.close() $ ui.textbutton(">>", yanchor='center', ypos=0.5, clicked= lambda: (add_page(), renpy.jump('save_menu')) ) $ ui.close() ##Page Number $ ui.sizer(maxwidth=182, xanchor='center', xpos=0.5) $ ui.frame(background=None,xanchor='center', xpos=0.5, xfill=True) $ ui.text("Page %s" % (page),style='pfont') ##Return Button $ ui.imagebutton(ui_return1, ui_return2, clicked=ui.jumps("_return"), xpos=1.0, xanchor='right', yanchor='center' ) $ ui.close()##closes general vbox $ ui.interact(suppress_overlay=True, suppress_underlay=True, mouse='mainmenu') return